<%@include file="includes/header.jsp" %>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="Model.*"%>
<%@page import="Controller.*"%>
<%@page import="java.sql.*" %> 
<%@page import="java.io.*" %>

<%
    String id = session.getAttribute("id").toString();
    Query q = new Query();
    Professor rs = q.getProf(id);
    ArrayList<Disciplina> lista = q.getListaDisc();
    ResultSet pref = q.getPref(id);
    if (pref.next()) {
        Integer disc_1 = pref.getInt("disc_1");
        Integer disc_2 = pref.getInt("disc_2");
        Integer disc_3 = pref.getInt("disc_3");
%>
<h1>Preferências</h1>
<div class="row-fluid">
    <div class="span12">
        <table class="table table-condensed table-striped table-bordered">
            <thead>
                <tr>                    
                    <th>Cod</th>
                    <th>Nome</th>
                    <th>Horas</th> 
                    <th class="text-center">Ver mais</i></th>
                    <th class="text-center">Gostaria</th>
                    <th class="text-center">Indiferente</th>
                    <th class="text-center">Não Gostaria</th>                    
                </tr>
            </thead>
            <tbody id="discs">
                <%
                    for (Disciplina disc : lista) {
                        if (disc_1 == disc.getId()) {
                            out.print("<tr class='disc1_h'>");
                        }
                        if (disc_2 == disc.getId()) {
                            out.print("<tr class='disc2_h'>");
                        }
                        if (disc_3 == disc.getId()) {
                            out.print("<tr class='disc3_h'>");
                        }
                        out.print("<td>" + disc.getCod() + "</td>");
                        out.print("<td>" + disc.getNome() + "</td>");
                        out.print("<td>" + disc.getCargahoraria() + "</td>");
                        out.print("<td class='text-center'><i class='icon icon-plus'></i></td>");
                        if (disc_1 == disc.getId()) { 
                            out.print("<td class='text-center'><input id='pref-" + disc.getId() + "' type='radio' name='disc_1' value='" + disc.getId() + "' xname='" + disc.getCod() + " - " + disc.getNome() + "' xid='" + disc.getId() + "' class='disc_1' checked></td>");
                        } else {
                            out.print("<td class='text-center'><input id='pref-" + disc.getId() + "' type='radio' name='disc_1' value='" + disc.getId() + "' xname='" + disc.getCod() + " - " + disc.getNome() + "' xid='" + disc.getId() + "' class='disc_1'></td>");
                        }
                        if (disc_2 == disc.getId()) {
                            out.print("<td class='text-center'><input id='pref2-" + disc.getId() + "' type='radio' name='disc_2' value='" + disc.getId() + "' xname='" + disc.getCod() + " - " + disc.getNome() + "' xid='" + disc.getId() + "' class='disc_2' checked></td>");
                        } else {
                            out.print("<td class='text-center'><input id='pref2-" + disc.getId() + "' type='radio' name='disc_2' value='" + disc.getId() + "' xname='" + disc.getCod() + " - " + disc.getNome() + "' xid='" + disc.getId() + "' class='disc_2'></td>");
                        }
                        if (disc_3 == disc.getId()) {
                            out.print("<td class='text-center'><input id='pref3-" + disc.getId() + "' type='radio' name='disc_3' value='" + disc.getId() + "' xname='" + disc.getCod() + " - " + disc.getNome() + "' xid='" + disc.getId() + "' class='disc_3' checked></td>");
                        } else {
                            out.print("<td class='text-center'><input id='pref3-" + disc.getId() + "' type='radio' name='disc_3' value='" + disc.getId() + "' xname='" + disc.getCod() + " - " + disc.getNome() + "' xid='" + disc.getId() + "' class='disc_3'></td>");
                        }
                        out.print("</tr>");
                    }
                %>
            </tbody>
        </table>                      
    </div> 
    <% } %>
    <div class="row-fluid">
        <div id="info"></div>
        <div id='opcoes'>
            <hr/>
            <dl class="dl-horizontal odiscs" pid='<%=session.getAttribute("id").toString()%>'>
                <dt>Opção 1:</dt>
                <dd class='odisc_1' xid=''></dd>
                <dt>Opção 2:</dt>
                <dd class='odisc_2' xid=''></dd>
                <dt>Opção 3:</dt>
                <dd class='odisc_3' xid=''></dd>
            </dl>
        </div>
    </div>
    <a class="btn btn-success" id="salvaPref">Salvar</a>

    <script src="js/dados.js"></script> 
    <%@include file="includes/footer.jsp" %>
